<template>
  <view class="reciveOrder">
    <AtList>
        <AtListItem
          v-for="(item,index) in state.orderList"
          :key="index"
          :title='item.category'
          :thumb='item.imageIds[0].url'
          :note='item.weight+"kg"'
          arrow='right'
          extraText='接单'
          :onClick="()=>{reciveOrder(item)}"
        />
    </AtList>
    <AtModal
      :isOpened="isOpened"
      :closeOnClickOverlay="false"
      title='确认提示'
      cancelText='再看看吧'
      confirmText='确定接单'
      :onCancel="handleCancel"
      :onConfirm="handleConfirm"
      :content="'请在'+state.appointmentTime+'之前安排上门,或者电话联系客户沟通,如有特殊情况请联系客服'"
    />
  </view>
</template>

<script setup>
import Taro,{showToast} from '@tarojs/taro'
import { onMounted, reactive, getCurrentInstance,ref, computed, createApp } from 'vue'
import dayjs from 'dayjs'
// import './recive-order.scss'

import request from "../../../utils/request";
const isOpened = ref(false)

const reciveOrder = (item)=>{
  isOpened.value = true
  console.log(item);
  state.appointmentTime = item.appointmentTime
  state.orderId = item._id
}
let state = reactive({
  orderList:[],
  appointmentTime:'',
  orderId:''
})

const getOrderList = async ()=>{
  let {data} = await request("/order/getList",'post',{status:1});
  state.orderList = data;
}

const handleConfirm = async()=>{
  let {msg} = await request("/order/takeOrder","post",{orderId:state.orderId})
  console.log(msg);
  showToast({
    title:'接单成功，请尽快联系用户安排上门'
  })
  isOpened.value = false
}



const handleClose = ()=>{

}
const handleCancel = ()=>{
  isOpened.value = false
}


onMounted(()=>{
  getOrderList()
})

</script>
